<script>
    // 成员模态表单页
    Vue.component('code-tally', {
        template: `
<el-dialog :visible.sync="dialogShow" width="600px" @close="closeModal">
    <h3 slot="title">
                <span >兑换码兑换</span>
    </h3>
    <el-form ref="form" :rules="memberRules" :model="memberForm" label-width="80px">

        <el-form-item label="兑换码" prop="serial_number" required>
        <el-input autocomplete="off" v-model="memberForm.serial_number"></el-input>
        </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
        <el-button @click="closeModal">取 消</el-button>
        <el-button type="primary" @click="handleMemberForm">确 定</el-button>
    </div>
</el-dialog>
    `,
        props: ['dialog-show','form-row'],
        computed: {
            currentTallyId() {
                return this.$store.state.currentTallyId
            },
            currentTally () {
                return this.$store.state.currentTally
            }
        },
        watch: {
            dialogShow:{
                handler (newVal) {},
                deep:true,
                immediate: true
            },
            formRow: {
                handler (newVal) {
                    this.memberForm = newVal
                },
                deep:true
            }
        },
        data:function() {
            return {
                memberForm:{},
                memberRules:{
                    serial_number: [
                        { required: true, message: '请输入兑换码', trigger: 'blur' }
                    ],
                },
            }
        },
        methods: {
            closeModal() {
                this.$emit('modalClose')
            },
            handleMemberForm() {
                let that = this
                that.memberForm.tally_id = that.currentTallyId
                axios.post('/api/tally/exchange-tally',that.memberForm,{
                    headers: {'token': loginToken},
                }).then(function(res) {
                    if(res.data.status === 'success'){
                        that.$message({
                            type: 'success',
                            message: '操作成功~'
                        })
                        that.$store.dispatch('checkTally')
                        that.memberForm={};
                        that.$emit('modalClose')
                    }else{
                        that.$message({
                            type: 'error',
                            message: '解析数据失败:'+res.data.error_message
                        })
                    }
                })
            }
        }
    })
</script>
